import down from '../../../../imgs/down.jpg'
import CommonUtils from '../../common/utils/CommonUtils'


export default class AddNumber extends React.Component{
    constructor(){
        super()
        this.state={
            num:1
        }
    }

    setCount(){
        const {num}=this.state
        this.props.setCount(num)
    }


    render(){
        const {num}=this.state
        return(
            <div className={'detail-top-types-addnum'}>
                <input
                    type="text"
                    value={num}
                    onChange={(e)=>{
                        let txt=e.target.value
                        if(txt==''){
                            this.setState({
                                num:e.target.value
                            })
                        }
                        if(!CommonUtils.isNum(txt)){
                            return
                        }
                        this.setState({
                            num:e.target.value-0
                        },this.setCount)
                    }}
                />
                <div>
                    <div
                        onClick={()=>{
                            this.setState({
                                num:num-0+1
                            },this.setCount)
                        }}
                        className={'detail-top-types-addnum-add'}>
                        <img src={down} alt=""/>
                    </div>
                    <div
                        onClick={()=>{
                            if(num==1){
                                return
                            }
                            this.setState({
                                num:num-1
                            },this.setCount)
                        }}
                        className={'detail-top-types-addnum-jian'}>
                        <img src={down} alt=""/>
                    </div>
                </div>

            </div>
        )
    }
}